
<template>
  <!--    vue框架-->
  <div id="app">
    <div class="login-form">
    <h2>这是注册页面</h2>
    <el-form ref="form" :model="form" label-width="80px">
<!--      <el-form-item label="手机号">-->
<!--        <el-input v-model="form.username"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="邮箱地址">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item label="邮箱验证">
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password1"></el-input>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input type="password" v-model="form.password2"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button>注册</el-button>
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>

<style scoped>
#app {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: rgba(113,143,229);
}
.el-input{
  margin-bottom: 15px;
}
.login-form {
  background-color: white;
  padding: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  width: 380px;
  height: 500px;
  margin-left: 500px;
  //border-radius: 4px;

  //max-width: 300px;
  //margin: 0 auto;
  //padding: 20px;
  border: 1px solid #ccc;
  border-radius: 15px;
  //text-align: center;
}
</style>

<script>
export default {
  data() {
    return {
      spanStyle: {
        cursor: 'pointer' //鼠标经过小手标志
      },

      user:{},
      form:{},
      captchaCode: '',
    };
  },
  methods: {
    wangji(){
      location.href='#/wangji'
    },
    zhuce(){
      location.href='#/zhuce'
    },
    generateCaptcha() {
      const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      let code = '';
      for (let i = 0; i < 4; i++) {
        code += chars.charAt(Math.floor(Math.random() * chars.length));
      }
      this.captchaCode = code;
    },
    login() {
      if (this.user.username==null || this.user.username==''){
        this.$message.error('请填写账号名称');
        return;
      }
      if (this.user.password==null || this.user.password==''){
        this.$message.error('请填写登录密码');
        return;
      }
      if (this.user.captcha==null || this.user.captcha==''){
        this.$message.error('请填写校验码');
        return;
      }else{
        if (this.user.captcha!=this.captchaCode){
          this.$message.error('校验码不正确');
          this.generateCaptcha(); // 重新生成校验码
          return;
        }
      }
      this.axios.post(`http://localhost:9009/user/login`,this.user).then(res => {
        if (res.data.code === 200) {
          this.$message.success("登录成功！欢迎您："+res.data.data.username);
          sessionStorage.setItem('userDB', JSON.stringify(res.data.data));
          location.href = '#/showye';
        } else {
          this.$message.error(res.data.data);
        }
      })
    },
  },
  created() {
    // this.generateCaptcha();
  }
};
</script>
